Repository navigation
feat(@schematics/angular): add use-library-builder migration to migrate from ng-packagr - #34232
alan-agius4 wants to merge 1 commit into
Conversation
f08895d to
8a5e256
Compare
dd4e9fb to
c6c9faf
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a new migration schematic, use-library-builder, designed to transition Angular library projects from the legacy ng-packagr builder to the new @angular/build:library builder. The migration handles transferring target options, discovering and mapping secondary entry points to package.json exports, and cleaning up obsolete configuration files and dependencies. Feedback on the implementation suggests refactoring a while loop in the directory traversal logic to avoid assignment within the loop condition, which improves code readability and prevents potential linter warnings.
8ac844b to
0788bdb
Compare
…te from ng-packagr Adds an optional migration for v22.3.0 to migrate library projects from ng-packagr to the @angular/build:library builder. The migration: - Discovers and converts primary and secondary entry points into the library package.json exports map. - Migrates assets and style preprocessor options from ng-package.json. - Configures compilationMode: 'full' for the development configuration unless already configured in tsconfig. - Deletes ng-package.json files and removes ngPackage from package.json. - Removes ng-packagr dependency and ensures @angular/build is present when no other ng-packagr targets remain.
0788bdb to
178b3d1
Compare
| ? { ...stylePreprocessorOptions } | ||
| : {}; | ||
|
|
||
| if (ngPackageConfig.lib.styleIncludePaths?.length) { |
There was a problem hiding this comment.
If buildTarget.options['stylePreprocessorOptions'] already defines includePaths in angular.json, this direct assignment will overwrite those existing paths.
To be consistent with how assets preserves pre-existing items (lines 245–261), consider combining existing includePaths with the migrated ones:
if (ngPackageConfig.lib.styleIncludePaths?.length) {
const existingIncludePaths = Array.isArray(existingPreprocessorOptions['includePaths'])
? (existingPreprocessorOptions['includePaths'] as string[])
: [];
const migratedIncludePaths = ngPackageConfig.lib.styleIncludePaths.map((p) =>
join(projectDir, p),
);
existingPreprocessorOptions['includePaths'] = [...existingIncludePaths, ...migratedIncludePaths];
}| } | ||
| } | ||
|
|
||
| return 'src/public-api.ts'; |
There was a problem hiding this comment.
Bug: In this case, won't we always fail? We've already confirmed that src/public-api.ts doesn't exist. Should we just error with a clear message?
| if (!current) { | ||
| break; | ||
| } |
There was a problem hiding this comment.
Suggestion: This seems redundant with the while (directories.length > 0) check above?
If we need this for type checking, maybe just while (true) above and leave the break; as the only way out of the loop?
Adds an optional migration for v22.3.0 to migrate library projects from
ng-packagrto the@angular/build:librarybuilder.The migration:
package.jsonexportsmap.ng-package.json.compilationMode: 'full'for thedevelopmentconfiguration unless already configured intsconfig.ng-package.jsonfiles and removesngPackagefrompackage.json.ng-packagrdependency and ensures@angular/buildis present when no otherng-packagrtargets remain.